﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace BHXH.Repository
{
    public partial class FrmExceptionNotifier : BHXH.Repository.FrmBase
    {
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            try
            {
                switch (keyData)
                {
                    case Keys.Enter:
                    case Keys.Escape:
                        this.Close();
                        break;
                }
                return base.ProcessCmdKey(ref msg, keyData);
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        private FrmExceptionNotifier(string exceptionDescription, string exceptionPosition)
        {
            InitializeComponent();
            this.AcceptButton = btnClose;
            txtExceptionDescription.Text = exceptionDescription;
            txtExceptionPosition.Text = exceptionPosition;
        }

        public static void ShowAndLog(Exception ex)
        {
            FrmExceptionNotifier frm = new FrmExceptionNotifier(ex.Message, ex.StackTrace.Substring(3));
            frm.ShowDialog();
            frm.Focus();
            frm.btnClose.Focus();
        }

        public static void Log(Exception ex)
        {
            FrmExceptionNotifier frm = new FrmExceptionNotifier(ex.Message, ex.StackTrace.Substring(3));
            frm.Close();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
